early_stopping = EarlyStopping(patience=10, restore_best_weights=True)
for epoch in range(num_epochs):
    # 训练代码
    early_stopping(val_loss, model)
    if early_stopping.early_stop:
        print("Early stopping")
        break
